package com.wf.ew.orderB.controller;

import com.wf.ew.common.BaseController;
import com.wf.ew.common.JsonResult;
import com.wf.ew.common.PageResult;
import com.wf.ew.common.utils.wechart.ScanCode;
import com.wf.ew.orderB.model.Customer;
import com.wf.ew.orderB.service.CustomerService;
import net.sf.json.JSONArray;
import org.apache.poi.ss.formula.functions.T;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * controller
 * @author : Doman
 * @date : 2020-04-13 13:56:30
 * @version ：1.0
 */

@Controller
@RequestMapping("/orderB/customer")
public class CustomerController extends BaseController {

	@Autowired
	private CustomerService customerService;
	
	/**
	 * 页面
	 **/
	@RequiresPermissions("customer:view")
	@RequestMapping("/getminiqrQr")
	public void getminiqrQr() throws Exception{
		String token = ScanCode.postToken();
		System.out.println(token);
		ScanCode.getminiqrQr("aa11", token);
	}
	/**
	 * 页面
	 **/
	@RequiresPermissions("customer:view")
	@RequestMapping()
	public String customer(){
		return "orderB/customer.html";
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("customer:view")
	@RequestMapping(value = "/list", produces = {"text/html;charset=UTF-8;"})
	@ResponseBody
	public String list(PageResult<T> page, Customer customer){
		return customerService.list(page, customer,getLoginUser());
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("customer:view")
	@RequestMapping(value = "/ajaxList", produces = {"text/html;charset=UTF-8;"})
	@ResponseBody
	public String ajaxList(Customer customer){
		return JSONArray.fromObject(customerService.list(customer,getLoginUser())).toString();
	}

	/**
	 * 新增
	 **/
	@RequiresPermissions("customer:add")
	@ResponseBody
	@RequestMapping("/add")
	public JsonResult add(Model model, Customer customer) {
		return customerService.add(customer, getLoginUser());
	}

	/**
	 * 修改
	 **/
	@RequiresPermissions("customer:update")
	@ResponseBody
	@RequestMapping("/update")
	public JsonResult update(Model model, Customer customer) {
		return customerService.update(customer, getLoginUser());
	}

	/**
	 * 批量删除
	 **/
	@RequiresPermissions("customer:delete")
	@RequestMapping("/delete")
	@ResponseBody
	public JsonResult delete(Customer customer ) {
		return customerService.delete(customer, getLoginUser());
	}

}
